package com.clwl.supervise.superviseapp.service.base;


import cn.hutool.core.net.NetUtil;
import com.clwl.supervise.superviseapp.entity.base.SysLoginInfor;
import com.clwl.supervise.superviseapp.mapper.base.SysLoginInforMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Service
public class SysLoginInfoService {

    @Resource
    private SysLoginInforMapper sysLoginInforMapper;


    public void insertLoginLog(HttpServletRequest request, String username, String status,String message,Long deptId) {
        SysLoginInfor logininfor = new SysLoginInfor();
        logininfor.setUsername(username);
        String  idAddr = "127.0.0.1";
        if (request != null) {
            idAddr = NetUtil.getMultistageReverseProxyIp(request.getRemoteAddr());
        }
        logininfor.setIpaddr(idAddr);
        logininfor.setLoginLocation("移动端登录");
        logininfor.setBrowser("移动端");
        logininfor.setUserAgent("移动端");
        logininfor.setOs("Android");
//        logininfor.setCompId(companyId);
        logininfor.setDeptId(deptId);
        logininfor.setMsg(message);
        logininfor.setLoginType("移动端");
        logininfor.setMobile("0");
        // 日志状态
        logininfor.setStatus(status);
        logininfor.setLoginTime(new Date());
        sysLoginInforMapper.insert(logininfor);
    }
}
